const ItemService = require('../services/item.service')

const itemService = new ItemService()

class ItemController {
  async findAll (ctx, next) {
    const data = await itemService.findAll()
    ctx.response.body = data
  }
  async addOne (ctx) {
    const body = ctx.request.body
    const data = await itemService.addOne(body)
    ctx.response.body = data
  }
  async findOne (ctx, next) {
    const id = ctx.request.params.id
    const data = await itemService.findOne(id)
    ctx.response.body = data[0]
  }
  async updateOne (ctx, next) {
    const id = ctx.request.params.id
    const body = ctx.request.body
    const data = await itemService.updateOne(id, body)
    ctx.response.body = data
  }
  async deleteOne (ctx, next) {
    const id = ctx.request.params.id
    const data = await itemService.deleteOne(id)
    ctx.response.body = data
  }
}

module.exports = ItemController